<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/17 0017
 * Time: 下午 1:54
 */

namespace app\admin\controller;

use app\admin\model\User as UserModel;
use think\Db;

class User extends Common
{
    /**
     * @title   用户列表
     */
    public function index()
    {
        $user = new UserModel();
        $list = $user::all();
        foreach ($list as $key => $value){
            $list[$key]['tz_integral'] = integral($value['id'],2);
            $list[$key]['mf_integral'] = integral($value['id'],1);
        }
        $this->assign('list',$list);
        return $this->fetch('admin/user/index');
    }

    /**
     * @title   普通会员变为经销商
     * @param null $id  会员id
     */
    public function distributor(&$id=null)
    {
        if(intval($id)) {
            $user = new UserModel();
            $save = $user::get($id);
            $save->u_type = 2;
            if ($save->save()) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        }else{
            $this->error('参数错误');
        }
    }
}